#include "Common.hlsli"

Texture2D texture0 : register(t0);
SamplerState sampler0 : register(s0);

float4 main(PSBasicVertex pin) : SV_TARGET
{
	float4 color = pin.color;
	if (draw_flags & DrawFlag_UseTexel)
	{
		color = texture0.Sample(sampler0, pin.tex);
	}
	if (draw_flags & DrawFlag_AlphaClip)
	{
		clip(color.a - 0.0001f);
	}

	float4 A, D, S;
	if (!ComputeAllLights(material, pin.norm, pin.posW, A, D, S))
		return color;

	// TODO reflection

	float4 litColor = color * (A + D) + S;
	litColor.a = material.Diffuse.a;
    return litColor;
}